function bindData(rowData){
	var unemployedId = rowData.unemployedId;
	$('#unemployedId').val(unemployedId);
	
	if(rowData.knry!='1'){
		$('#addAidRecordButton').linkbutton('disable');
		$('#updateAidRecordButton').linkbutton('disable');
		$('#delAidRecordButton').linkbutton('disable');
	} else if(rowData.knry=='1'){
		$('#addAidRecordButton').linkbutton('enable');
		$('#aupdateAidRecordButton').linkbutton('enable');
		$('#delAidRecordButton').linkbutton('enable');	
	}
	
    $('#aidRecordGrid').datagrid({ 
    	url:'jobless/difficultyServer/getAidRecordList',  
        idField:'id',
        queryParams:{
        	unemployedId:unemployedId
	    },
        rownumbers:true,
        fit:true,
        fitColumns:true,
        singleSelect:true,
        pagination:true,
        columns:[[
                  {title:'主键',field:'id',rowspan:2,hidden:'true'}, 
                  {title:'失业人员主键',field:'unemployedId',rowspan:2,hidden:'true'},
                  {field:'aiddate',title:'时间',width:100,rowspan:2,align:'center',
                	     formatter:function(data){ 
                	    	 if(data!=null){
                	    		 var df = new Date(data);  
                                 return df.format("yyyy-MM-dd");       			   
       		                 } else{
       		        	         return null;
       		                 }
       	                 }},  
                  {field:'assistant',title:'就业协理员',width:100,rowspan:2,align:'center'},
                  {title:'提供就业服务情况',colspan:4,align:'center'},
                  {title:'援助效果',colspan:2,align:'center'},
                  {field:'remark',title:'备注',width:90,rowspan:2,align:'center'},
                  {field:'others',title:'其他',width:90,rowspan:2,align:'center'}  
                ],[
                  {field:'guide',title:'职业指导',width:100,align:'center'}, 
                  {field:'intruduce',title:'职业介绍',width:100,align:'center'}, 
                  {field:'training',title:'技能培训',width:100,align:'center'}, 
                  {field:'jobfair',title:'参加招聘会',width:100,align:'center'}, 
                  {field:'employdate',title:'就业时间',width:100,align:'center',
                	     formatter:function(data){ 
                	    	 if(data!=null){
                	    		 var df = new Date(data);  
                                 return df.format("yyyy-MM-dd");       			   
    		                 } else{
    		        	         return null;
    		                 }
    	                 }},  
                  {field:'headto',title:'就业去向',width:100,align:'center'}                 
                ]]    	
    }); 
}

$("#addAidRecord").window({
	onClose:function(data){
		$('#addAidRecordForm').form('clear');
	}  		      
});

function addAidRecord(){
	var curr_time = new Date();
	var strDate = curr_time.getFullYear()+"-"+(curr_time.getMonth()+1)+"-"+curr_time.getDate();
	$('#aidRecordAdd_aiddate').datebox('setValue',strDate);	
	$('#addAidRecord').window('open');
}

/**
 * 添加困难人员就业援助记录
 */
function insertAidRecord(){
	$('#addAidRecordForm').form('submit',{
		url:'jobless/difficultyServer/insertAidRecord',
		queryParams:{
			unemployedId: $('#unemployedId').val()
		},
		success: function(data){
			data =  $.parseJSON(data);
			if(data.success == 'true'){
				$.messager.alert('提示','添加成功','info');
				$('#addAidRecord').window('close');
				$('#addAidRecordForm').form('clear');
				$('#aidRecordGrid').datagrid('reload');
			}else{
				$.messager.alert('提示',data.message,'info');
			}
		}
	});
}

/**
 * 回显一条困难人员就业援助记录
 * 
 */
function getAidRecord(){
	var rowData = $('#aidRecordGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$('#modifyAidRecord').window('open');
		//alert(rowData.id);
		$.ajax({
			url:'jobless/difficultyServer/getAidRecordInfo',
			type:'post',
			data:{
				id:rowData.id
			},
			success: function (data) {
				if(data==null){
					$('#modifyAidRecordForm').form('clear');
				}else{
					$('#modifyAidRecordForm').form('load',data);
				}
	        },
	        error:function(data){
	        	$('#modifyAidRecordForm').form('clear');
	        }
		});
	}
}

/**
 * 修改一条困难人员就业援助记录
 * 
 */
function modifyAidRecord(){
	var modifyFlag = $('#modifyAidRecordForm').form('validate');
	if(modifyFlag==false){
		$.messager.alert('提示','表单填写不正确');
		return;
	}else{
		$.ajax({
			url:'jobless/difficultyServer/updateAidRecord',
			type:'post',
	        async: false,
	        data:$('#modifyAidRecordForm').serialize(),
	        success:function(data){
	        	data =  $.parseJSON(data);
		        if(data.success == 'true'){
		        	$.messager.alert('提示','保存成功','info');
			        $('#modifyAidRecord').window('close');
			        $('#modifyAidRecordForm').form('clear');
			        $('#aidRecordGrid').datagrid('reload');
					$('#aidRecordGrid').datagrid('unselectAll');
		        }else{
		        	$.messager.alert('提示',data.message,'info');

		        }
	        },
	        error:function(data){
	        	alert("ajax发生错误！");	
	        }
        });
	}	
}

/**
 * 删除一条困难人员就业援助记录
 * 
 */
function delAidRecord(){
	var rowData = $('#aidRecordGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$.messager.confirm('提示','确定要删除吗？',function(r){
			if(r){
				$.ajax({
					url:'jobless/difficultyServer/deleteAidRecord',
					type:'post',
					data:{
						id:rowData.id
					},
					success:function(data){
						data =  $.parseJSON(data);
						if(data.success == 'true'){
							$.messager.alert('提示','删除成功','info');
							$('#aidRecordGrid').datagrid('reload');
							$('#aidRecordGrid').datagrid('unselectAll');
						}else{
							$.messager.alert('提示',data.message,'info');
						}
					}
				});
			}
		});
	}
}

/**
 * 日期格式化
 * @param value
 * @param row
 * @returns {String}
 */
function formatterDate(value) {
    var date = new Date(value);
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}

function parserDate(s){
	//alert("parserDate");
	var t = Date.parse(s);
	if (!isNaN(t)){
		return new Date(t);
	} else {
		return new Date("1975-08-01");
	}
	
    /*if(!s) return new Date();
	var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
	if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
		return new Date(y,m-1,d);
	}else{
		return new Date();
	}*/
	
}